package com.learn.exchange;

import com.learn.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/08/23
 * @description ch05 交换机
 * 扇出交换机
 */
public class DirectEmit {
    public static final String EXCHANGE_NAME = "direct_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        System.out.println("emit ready-------------------");
        for (int i = 0; i < 3; i++) {
            String msg = "msg0" + i;
            channel.basicPublish(EXCHANGE_NAME,
                    i % 2 == 0 ? "warning" : "info",
                    null,
                    msg.getBytes(StandardCharsets.UTF_8));
        }
    }
}
